﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using ERP.Business.Company.Policy;
using ERP.Business.DataTypes.Company;

namespace ERP.UI.SystemAdministrator
{
    public partial class CompanyInformation
    {
        public CompanyInformation()
        {
            this.InitializeComponent();

            // Insert code required on object creation below this point.
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            lblSavedSuccessfully.Visibility = lblCannotSave.Visibility = lblInvalidFields.Visibility = Visibility.Hidden;

            if (tbName.Text.Trim().Equals(string.Empty) || tbAddress.Text.Trim().Equals(string.Empty) || tbEmail.Text.Trim().Equals(string.Empty) ||
                tbFax.Text.Trim().Equals(string.Empty) || tbPhone.Text.Trim().Equals(string.Empty) || tbSSN.Text.Trim().Equals(string.Empty) ||
                tbTaxCode.Text.Trim().Equals(string.Empty) || tbWebsite.Text.Trim().Equals(string.Empty))
            {
                lblInvalidFields.Visibility = Visibility.Visible;
            }
            else
            {
                ERP.Business.DataTypes.Company.Company ci = new ERP.Business.DataTypes.Company.Company();
                ci.Name = tbName.Text;
                ci.Address = tbAddress.Text;
                ci.EmailAddress = tbEmail.Text;
                ci.FaxNumber = tbFax.Text;
                ci.PhoneNumber = tbPhone.Text;
                ci.SocialSecurityNumber = tbSSN.Text;
                ci.TaxCode = tbTaxCode.Text;
                ci.WebSite = tbWebsite.Text;

                if (ERP.Business.Company.InformationManager.SaveCompanyInformation(ci))
                    lblSavedSuccessfully.Visibility = Visibility.Visible;
                else
                    lblCannotSave.Visibility = Visibility.Visible;
            }
        }


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ERP.Business.DataTypes.Company.Company ci = ERP.Business.Company.InformationManager.GetCompanyInformation();

            if (ci != null)
            {
                tbAddress.Text = ci.Address;
                tbEmail.Text = ci.EmailAddress;
                tbFax.Text = ci.FaxNumber;
                tbName.Text = ci.Name;
                tbPhone.Text = ci.PhoneNumber;
                tbSSN.Text = ci.SocialSecurityNumber;
                tbTaxCode.Text = ci.TaxCode;
                tbWebsite.Text = ci.WebSite;
            }
        }
    }
}